package com.ruoyi.risk.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.risk.domain.RiskStrategies;
import com.ruoyi.risk.service.IRiskStrategiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 策略脚本配置信息Controller
 *
 * @author ruoyi
 * @date 2021-11-13
 */
@RestController
@RequestMapping("/strategies")
public class RiskStrategiesController extends BaseController
{
    @Autowired
    private IRiskStrategiesService riskStrategiesService;

    /**
     * 查询策略脚本配置信息列表
     */
    @RequiresPermissions("risk:strategies:list")
    @GetMapping("/list")
    public TableDataInfo list(RiskStrategies riskStrategies)
    {
        startPage();
        List<RiskStrategies> list = riskStrategiesService.selectRiskStrategiesList(riskStrategies);
        return getDataTable(list);
    }

    /**
     * 导出策略脚本配置信息列表
     */
    @RequiresPermissions("risk:strategies:export")
    @Log(title = "策略脚本配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskStrategies riskStrategies) throws IOException
    {
        List<RiskStrategies> list = riskStrategiesService.selectRiskStrategiesList(riskStrategies);
        ExcelUtil<RiskStrategies> util = new ExcelUtil<RiskStrategies>(RiskStrategies.class);
        util.exportExcel(response, list, "策略脚本配置信息数据");
    }

    /**
     * 获取策略脚本配置信息详细信息
     */
    @RequiresPermissions("risk:strategies:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(riskStrategiesService.selectRiskStrategiesById(id));
    }

    /**
     * 新增策略脚本配置信息
     */
    @RequiresPermissions("risk:strategies:add")
    @Log(title = "策略脚本配置信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskStrategies riskStrategies)
    {
        return toAjax(riskStrategiesService.insertRiskStrategies(riskStrategies));
    }

    /**
     * 修改策略脚本配置信息
     */
    @RequiresPermissions("risk:strategies:edit")
    @Log(title = "策略脚本配置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskStrategies riskStrategies)
    {
        return toAjax(riskStrategiesService.updateRiskStrategies(riskStrategies));
    }

    /**
     * 删除策略脚本配置信息
     */
    @RequiresPermissions("risk:strategies:remove")
    @Log(title = "策略脚本配置信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(riskStrategiesService.deleteRiskStrategiesByIds(ids));
    }
}
